package com.play;

import com.play.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {

  @RequestMapping("/")
  public String getUsers(Map<String, Object> model) {
    return "user";
  }

  @RequestMapping("user/user-table")
  public String getUsersByPage(Map<String, Object> model, @RequestParam("page") Integer page) {

    List<User> users = new ArrayList<>();
    for (int i = 1; i <= 5; i++) {
      User user = new User();
      user.setId((page - 1) * 5 + i);
      user.setFirstName("John");
      user.setLastName("berk_" + page);
      users.add(user);
    }
    model.put("users", users);
    return "user-table";
  }
}